/**
 * Created by ls.c on 2016/11/3.
 */


import {getjson, postjson, putjson, deljson} from '../../requestJson'

/**
 * 面包屑
 */
export const fetchBreadcrumb = ({commit}, names) => {

	commit('FETCH_ADMIN_BREADCRUMB', names)

}

/**
 * 导航栏选中状态
 */
export const fetchAdminNavStatus = ({commit}, status) => {

	commit('FETCH_ADMIN_NAV_STATUS', status)

}
/**
 * 用户信息
 */
export const fetchRole = ({ commit }, params) =>{

	const url = 'info'
	const query =  params
	return getjson({url, query}, commit)
		.then((json) => {
			if (json.success) {

				return commit('FETCH_ROLE_SUCCESS', json.result)
			}
			return alert(json.resultMsg)
		})
		.catch((error) => {
			return Promise.reject(error)
		})

}
/**
 * 获取套餐列表(基础)
 */
export const fetchBasicsPackage = ({ commit }, params) =>{

	const url = 'meal/list'
	const query = `cardTypeId=${params.cardTypeId}&operatorId=${params.operatorId}&packageType=basics`
	return getjson({url, query}, commit)
		.then((json) => {
			if (json.success) {

				return commit('FETCH_BASICS_PACKAGE_SUCCESS', json)
			}
			return alert(json.resultMsg)
		})
		.catch((error) => {
			return Promise.reject(error)
		})

}
/**
 * 获取套餐列表(叠加包)
 */
export const fetchOverlyingPackage = ({ commit }, params) =>{

	const url = 'meal/list'
	const query = `cardTypeId=${params.cardTypeId}&operatorId=${params.operatorId}&packageType=overlying`
	return getjson({url, query}, commit)
		.then((json) => {
			if (json.success) {

				return commit('FETCH_OVERLYING_PACKAGE_SUCCESS', json)
			}
			return alert(json.resultMsg)
		})
		.catch((error) => {
			return Promise.reject(error)
		})

}


/**
 * 行业信息
 */
export const fetchIndustry = ({ commit }, params) =>{

	const url = 'api/industry'
	const query =  params
	return getjson({url, query}, commit)
		.then((json) => {
			if (json.success) {
				return commit('FETCH_INDUSTRY_SUCCESS', json)
			}
			return alert(json.resultMsg)
		})
		.catch((error) => {
			return Promise.reject(error)
		})

}
/**
 * 获取业务员
 */
export const fetchSalesman = ({ commit }, params) =>{

	const url = 'client/querySalesman'
	const query =  params
	return getjson({url, query}, commit)
		.then((json) => {
			if (json.success) {
				return commit('FETCH_SALESMAN_SUCCESS', json)
			}
			return alert(json.resultMsg)
		})
		.catch((error) => {
			return Promise.reject(error)
		})

}
/**
 * 获取客户名单
 */
export const fetchCustomers= ({ commit }, params) =>{

	const url = 'client/queryCustomer'
	const query =  `salesId=${params.id}`
	return getjson({url, query}, commit)
		.then((json) => {
			if (json.success) {
				return commit('FETCH_CUSTOMERS_SUCCESS', json)
			}
			return alert(json.resultMsg)
		})
		.catch((error) => {
			return Promise.reject(error)
		})

}
/**
 * 获取卡划拨
 */
export const fetchCardTransfer= ({ commit }, params) =>{

	const url = 'card/transfer'
	const query =  `operatorId=${params.operatorId}&cardTypeId=${params.cardTypeId}&buyNum=${params.buyNum}&packageCode=${params.packageCode}`
	return getjson({url, query}, commit)
		.then((json) => {
			if (json.success) {
				return commit('FETCH_CARD_TRANSFER_SUCCESS', json)
			}
			return commit('FETCH_CARD_TRANSFER_SUCCESS', json)
		})
		.catch((error) => {
			return Promise.reject(error)
		})

}
/**
 * 获取套餐类型
 */
export const fetchPackageType= ({ commit }, params) =>{

	const url = 'api/mealType'
	const query =  ''
	return getjson({url, query}, commit)
		.then((json) => {
			if (json.success) {
				return commit('FETCH_PACKAGE_TYPE_SUCCESS', json)
			}
			return commit('FETCH_PACKAGE_TYPE_SUCCESS', json)
		})
		.catch((error) => {
			return Promise.reject(error)
		})

}
/**
 * 获取套餐列表
 */
export const fetchPackageList= ({ commit }, params) =>{

	const url = 'meal/sale'
	const query =  `operatorId=${params.operatorId}&mealType=${params.mealType}`
	return getjson({url, query}, commit)
		.then((json) => {
			if (json.success) {
				return commit('FETCH_PACKAGE_LIST_SUCCESS', json)
			}
			return commit('FETCH_PACKAGE_LIST_SUCCESS', json)
		})
		.catch((error) => {
			return Promise.reject(error)
		})

}































